import pandas as pd

data = {
    "Name": ["Alice", "Bob", "Tom", "Jerry", "David"],
    "Age": [22, 23, 24, 25, 26],
    "City": ["Beijing", "Shanghai", "Guangzhou", "Shenzhen", "Hangzhou"],
}
df = pd.DataFrame(data)

# 1.loc[行标签, 列标签], iloc[行索引, 列索引]
print("选定行 loc[0]:\n", df.loc[0])  # 选定行
print("选定行 iloc[1]:\n", df.iloc[1])  # 选定行
print("选定多行 iloc[1:3]:\n", df.iloc[1:3])  # 选定 多行
print("选定行-列 iloc[1,[1]]:\n", df.iloc[1, [1]])  # 选定 行-列
print("选定行-多列 iloc[1,[0,2]]:\n", df.iloc[1, [0, 2]])  # 选定 行-多列
"""
定行 loc[0]:
Name      Alice
Age          22
City    Beijing
Name: 0, dtype: object

选定行 iloc[1]:
Name         Bob
Age           23
City    Shanghai
Name: 1, dtype: object

选定多行 iloc[1:3]:
   Name  Age       City
1  Bob   23   Shanghai
2  Tom   24  Guangzhou

选定行-列 iloc[1,[1]]:
 Age    23
Name: 1, dtype: object

选定行-多列 iloc[1,[0,2]]:
Name         Bob
City    Shanghai
Name: 1, dtype: object
"""

# 2. at选定 [行,列]
print("at[1, 'Age']:", df.at[1, "Age"])
print("iat[2, 0]:", df.iat[1, 0])
""" 
at[1, 'Age']: 23
iat[2, 0]: Bob
"""

# 3. [列][行] 选定
print(df["Name"][0])